package collection;

import java.util.Deque;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Stack;

/**
 * @author Cheng Jun
 * Description: 双端队列学习
 * @version 1.0
 * @date 2021/12/20 20:53
 */
public class DequeStudy {

    public static void main(String[] args) {
        Stack<Integer> stack = new Stack<>();
        stack.push(1);
        stack.push(2);
        stack.push(3);
        Deque<Integer> integerDeque = new LinkedList<>();
        integerDeque.add(3);
        integerDeque.add(1);
        integerDeque.add(0);
        // 注意 iterator() 要强转一下，Iterator接口中方法太少
        ListIterator<Integer> iterator = (ListIterator) integerDeque.iterator();
        while (iterator.hasNext()) {
            Integer next = iterator.next();
            System.out.println(next);
            if (next <= 2) {
                iterator.set(2);
            }
        }
        System.out.println(integerDeque.size());
    }
}
